<?php

/** libraries
 * http://docs.joomla.org/JToolBarHelper
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

class bgViewbg extends JView
{
	// Overwriting JView display method
	function display($tpl = null) 
	{
	   
       $model = $this->getModel();
       $aut = new bgAuthorize(); 
       
        switch(JRequest::getVar('task')){
            case 'error':
                $this->row = (object)JRequest::getVar('jform');
                JToolBarHelper::title( '指導者情報作成', 'contacts.png' );
                JToolBarHelper::save2copy('savetemp','一時保存');
                JToolBarHelper::save('save','登録');
       	        JToolBarHelper::cancel('cancel', 'キャンセル');
                
                $this->listjob=$model->getAllJobmList();
                $this->listpref=$model->getAllPrefList();
                //GET DATA LKDT
                $this->lkdt=$model->getAllLkdt();
                $a=$model->getTotalLkdt();
                for($i=1;$i<=$a;$i++)
                {
                    $this->row->OCBA_PUTF = 1;
                    $this->list['chl'.$i] = &JRequest::getVar('chl'.$i);
                }
                //GET DATA HUMAN
                $this->human=$model->getAllHuman();
                $b=$model->getTotalHuman();
                for($i=1;$i<=$b;$i++)
                {
                    $this->list['chh'.$i] = &JRequest::getVar('chh'.$i);
                }
                $this->setLayout('a01220');
                
                break;
                
            case 'edit':
                $cid = JRequest::getVar('cid');
                $cid = is_array($cid) ? $cid[0] : $cid;
                if($cid){
                    $this->row = $model->load($cid);
                }else{
                    //die('Not found');
                    die("データは見つかりませんでした");
                }
                JToolBarHelper::title( '指導者情報編集', 'contacts.png' );
                JToolBarHelper::save2copy('savetemp','一時保存');
                JToolBarHelper::save('save','登録');
       	        JToolBarHelper::cancel('cancel', 'キャンセル');
                
                $this->listjob=$model->getAllJobmList();
                $this->listpref=$model->getAllPrefList();
                //GET DATA LKDT
                $this->lkdt=$model->getAllLkdt();
                $a=$model->getTotalLkdt();
                for($i=1;$i<=$a;$i++)
                {
                    $this->list['chl'.$i] = &JRequest::getVar('chl'.$i);
                }
                //GET DATA HUMAN
                $this->human=$model->getAllHuman();
                $b=$model->getTotalHuman();
                for($i=1;$i<=$b;$i++)
                {
                    $this->list['chh'.$i] = &JRequest::getVar('chh'.$i);
                }
                $this->setLayout('a01220');
                
                break;
             
            case 'popup_town':
                // Get data from the model
                $this->list_center =& $model->getAllListCenter();  
                //$this->pagination =& $this->get('PaginationTown');                               
                $this->setLayout('popup_town');
            break;
             
            case 'add':
            	JToolBarHelper::title( '指導者情報作成', 'contacts.png' );
                JToolBarHelper::save2copy('savetemp','一時保存');
                JToolBarHelper::save('save','登録');
       	        JToolBarHelper::cancel('cancel', 'キャンセル');
                
                $this->listjob=$model->getAllJobmList();
                $this->listpref=$model->getAllPrefList();
                $this->cocm=$model->getAllCocm();
                //CHECKBOX LKDT
                $this->lkdt=$model->getAllLkdt();
                $a=$model->getTotalLkdt();
                for($i=1;$i<=$a;$i++)
                {
                    $this->list['chl'.$i] = &JRequest::getVar('chl'.$i);
                }
                //CHECKBOX HUMAN
                $this->human=$model->getAllHuman();
                $b=$model->getTotalHuman();
                for($i=1;$i<=$b;$i++)
                {
                    $this->list['chh'.$i] = &JRequest::getVar('chh'.$i);
                }
                
                //get max coch_code
                //$maxid=$model->getMaxCOCH_CODE();
//                $this->coch_code=$maxid+1;
                
                $this->setLayout('a01210');
            	break;
             
             case 'save':
                
             break;
            	    
            default :
                
                $this->list['center'] = &JRequest::getVar('center');
                $this->list['unit'] = &JRequest::getVar('unit');
                $this->list['term'] = &JRequest::getVar('term');
                $this->list['area'] = &JRequest::getVar('area');
                $this->list['human_rs'] = &JRequest::getVar('human_rs');
                $this->list['ld_meeting'] = &JRequest::getVar('ld_meeting');
                $this->list['ls_date'] = &JRequest::getVar('ls_date');
                $this->list['pref'] = &JRequest::getVar('pref');
               
                $this->list['namecc'] = &JRequest::getVar('namecc');
                $this->list['nameld'] = &JRequest::getVar('nameld');
                
                //CHECKBOX cocm
                $this->lkdt=$model->getAllCocm();
                $c=$model->getTotalCocm();
                for($i=1;$i<=$c;$i++)
                {
                    $this->list['chb'.$i] = &JRequest::getVar('chb'.$i);
                }
                $this->colis = $model->loadcoli($cid[0]);
                $this->ocba=$model->getAllOCBA();
                $this->area=$model->getAllArea();
                $this->cocm=$model->getAllCocm();
                //CHECKBOX LKDT
                $this->lkdt=$model->getAllLkdt();
                $a=$model->getTotalLkdt();
                for($i=1;$i<=$a;$i++)
                {
                    $this->list['chll'.$i] = &JRequest::getVar('chll'.$i);
                }
                //CHECKBOX HUMAN
                $this->human = $model->getAllHuman();
                $b=$model->getTotalHuman();
                for($i=1;$i<=$b;$i++)
                {
                    $this->list['chhh'.$i] = &JRequest::getVar('chhh'.$i);
                }
                $area_code=0;
                $this->pref=$model->getAllPref($area_code);
                
                
                //Kiem tra user quyen 11
                if($aut->checkEditOwn()){
                    $user_id = $aut->getUserID();
                    $this->list['OCBA_CODE'] = $model->getOCBA_CODEFromUser($user_id);
                    $this->rows = $model->getAll($this->list);
                }else{
                    $this->rows = $model->getAll($this->list);
                }
                
                $this->pagination = $this->get('Pagination');
                $this->setLayout('a01200');
                
                JToolBarHelper::title( '指導者情報管理', 'contacts.png' ); 
		}
        
		parent::display();
	}
}




